<?php

namespace app\api\controller;


//房屋的数据分析
use app\common\controller\Api;
use app\api\model\house\HouseOrder;

class Housedataanalyse extends Api
{

    protected $noNeedRight = ['*'];



    //汇总表
    public function orderdata()
    {
        $year = input('year','2025');
        $order_type = input('order_type',0);
        $month_list = getMonthlyTimestamps($year);
        $data = [];
        $where = ['owner_id'=>$this->auth->id,'pay_status'=>1];
        if ($order_type)$where['order_type'] = $order_type;
        foreach ($month_list as $k=>$v){
            //单量
            $order_count = HouseOrder::where($where)
                ->where('createtime', 'between time', [$v['start_timestamp'], $v['end_timestamp']])
                ->count();
            //收益
            $order_money = HouseOrder::where($where)
                ->where('createtime', 'between time', [$v['start_timestamp'], $v['end_timestamp']])
                ->sum('pay_money');
            //收益积分
            $order_score = HouseOrder::where($where)
                ->where('createtime', 'between time', [$v['start_timestamp'], $v['end_timestamp']])
                ->sum('earn_score');
            $data[] = [
                'date'=>$v['month'],
                'order_count'=>$order_count,
                'order_money'=>$order_money,
                'order_score'=>$order_score
            ];
        }

        $this->success('',$data);
    }


}